package 网络编程;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class Inetaddress类的使用 {
    public static void main(String[] args) throws UnknownHostException {
        //1.获取InetAddress的对象,通过getByAddress确定主机名称的ip地址。
        InetAddress address = InetAddress.getByName("moonlight");
        System.out.println(address);


        //如果局域网中没有这个ip是获取不到主机名字的
        String name = address.getHostName();
        System.out.println(name);

        String ip = address.getHostAddress();
        System.out.println(ip);

    }
}
